package webdev.utils;

public class ListViewScrollDetectorUtil {
	private static int lastFirstItem = 0;
	private static int lastTopOfFristVisibleItem = 0;
	public static final int SCROLL_UP = 0;
	public static final int SCROLL_DOWN = 1;
	public static final int SCROLL_STOP = 2;

	public static int isScrollUp(int firstVisibleItem, int topOfFristVisibleItem) {
		int result;

		if (firstVisibleItem == lastFirstItem) {
			// Case scroll down
			if (topOfFristVisibleItem > lastTopOfFristVisibleItem) {
				result = SCROLL_DOWN;
			// Case scroll up
			} else if (topOfFristVisibleItem < lastTopOfFristVisibleItem) {
				result = SCROLL_UP;
			} else {
				result = SCROLL_STOP;
			}
			lastTopOfFristVisibleItem = topOfFristVisibleItem;
		// Case switch to other item
		} else {
			lastTopOfFristVisibleItem = topOfFristVisibleItem;
			lastFirstItem = firstVisibleItem;
			result = SCROLL_STOP;
		} // end if

		return result;
	}
}
